package cn.okcmd.log_logback.subtest.defconf;

import ch.qos.logback.classic.spi.Configurator;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * create by caoqg on 2021/7/16
 * 功能说明: 测试java serviceLoader
 */
public class ServiceLoaderTest {
    public static void main(String[] args) {

        Class<Configurator> testClazz = Configurator.class;
        ServiceLoader<Configurator> sl = ServiceLoader.load(testClazz);

        System.out.println("开始加载spi:" + testClazz);
        Iterator<Configurator> it = sl.iterator();
        while (it.hasNext()) {
            Configurator next = it.next();
            System.out.println("加载到一个实现实例:"+next);
        }
        System.out.println("测试结束");
    }
}
